import java.util.Collections;
import java.util.Scanner;
import java.util.Deque;
import java.util.ArrayDeque;
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86186
 * Date: 2023-10-29
 * Time: 16:31
 */
public class Test {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        int m = in.nextInt(), n = in.nextInt();
        int[][] maze = new int[m + 2][n + 2];
        for (int i = 0; i <= m + 1; i++) {
            for (int j = 0; j <= n + 1; j++) {
                if (i == 0 || i == m + 1 || j == 0 || j == n + 1) {
                    maze[i][j] = 1;
                }else {
                    maze[i][j] = in.nextInt();
                }
            }
        }
        Deque<String> deque = new ArrayDeque<>();
        deque.push("(0,0)");
        int x = 1, y = 1;
        while (true) {
            if (x == m && y == n) break;
            if (maze[x + 1][y] == 0) {
                x++;
                deque.push("(" + (x - 1) + "," + (y - 1) + ")");
            }else if (maze[x][y + 1] == 0) {
                y++;
                deque.push("(" + (x - 1) + "," + (y - 1) + ")");
            }else {
                maze[x][y] = 1;
                deque.pop();
                if (deque.isEmpty()) break;
                String t = deque.peek();
                x = t.charAt(1) - '0' + 1;
                y = t.charAt(3) - '0' + 1;
            }
        }
        while (!deque.isEmpty()) {
            String t = deque.removeLast();
            System.out.println(t);
        }
    }

}
